// void, Obj This, Obj Bld

Wagon this;
Building bld;
point pt;

this = This.AsWagon();
bld = Bld.AsBuilding();

if(.IsValid){
	if(bld.IsValid){
		
		.SetEntering(true);
		pt = bld.GetEnterPoint(this);
		while(!.GotoEnter(pt, 0, 2000, false, 2500))
		{
			if(.IsEnemy(bld))
				return; /// the next command should be to return back
			if(bld.IsHeirOf("BaseRuins")) 
				return;
			if(bld.IsHeirOf("Catapult")) 
				return;
		}

		if (.restype == 1) { // food
			if(.amount > 1)
				bld.settlement.SetFood(bld.settlement.food + .amount);
		} else { // gold
			if(.amount > 0){
				bld.settlement.SetGold(bld.settlement.gold + .amount);
				bld.settlement.GoldConverted(.amount);
			}
		}
		.SetFood(0);//WTF?
		.SetGold(0);
		if(.IsHeirOf("ShipSFishing")){
			Wagon wagon;
				
			wagon = bld.settlement.CreateShip("ShipSFishing").AsWagon;
			if (wagon.IsValid){
				wagon.SetFood(1);       
				wagon.SetName(bld.name);  
			}
		}
		.Erase();
	}
}